package com.wechat.page.property;

import com.swak.fx.support.Property;
import com.swak.utils.StringUtils;
import com.wechat.login.LoginService;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
public class LoginProperty implements Property {

	private final StringProperty idProperty = new SimpleStringProperty();
	private final StringProperty nickNameProperty = new SimpleStringProperty();
	private final ObjectProperty<byte[]> headimgProperty = new SimpleObjectProperty<>();

	public LoginProperty() {
		LoginService.me().addChangeListener((login) -> {
			this.idProperty.set(login != null ? login.getId() : StringUtils.EMPTY);
			this.nickNameProperty.set(login != null ? login.getNickName() : StringUtils.EMPTY);
			this.headimgProperty.set(login != null ? login.getHeadimg() : null);
		});
	}
}
